package com.ddkj.netty.server.websocket.parkingwebsocket;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;


public class ParkingInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast("http-codec", new HttpServerCodec());
        pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
        socketChannel.pipeline().addLast("http-chunked", new ChunkedWriteHandler());
        /**
         *第一个参数 60  表示读操作空闲时间
         *第二个参数 20  表示写操作空闲时间
         *第三个参数 60*10 表示读写操作空闲时间
         *第四个参数 单位
         */
        socketChannel.pipeline().addLast("ping", new IdleStateHandler(6, 5, 4, TimeUnit.MINUTES));

        pipeline.addLast("handler", new WebSocketParkingServerHandler());
    }

}
